package com.czy.owner.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.entity.CarInfo;
import com.czy.owner.widget.RoundImageView;

import org.xutils.common.Callback;
import org.xutils.x;

import java.util.List;

/**
 * Created by hedepu on 2017/09/26.
 * 违章选择车库
 */
public class GarageSelectCarAdapter extends BaseRecyclerAdapter<CarInfo, GarageSelectCarAdapter.GarageSelectCarHolder> {


    public GarageSelectCarAdapter(Context context, List<CarInfo> data) {
        super(context, data, false, false);
    }


    @Override
    public GarageSelectCarHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.item_select_garage_recycler, parent, false);
        return new GarageSelectCarHolder(view);
    }


    @Override
    public void onBindViewHolder(final GarageSelectCarHolder holder, final int position) {
        super.onBindViewHolder(holder, position);
        holder.bindData(data.get(position));
    }

    public class GarageSelectCarHolder extends BaseRecyclerAdapter.ViewHolder {
        private RoundImageView ivAvatar;
        private TextView tv_car_id;
        private TextView tv_item_degree;


        public GarageSelectCarHolder(View itemView) {
            super(itemView);
            ivAvatar = (RoundImageView) itemView.findViewById(R.id.iv_garage_item_avatar);
            tv_car_id = (TextView) itemView.findViewById(R.id.tv_car_id);
            tv_item_degree = (TextView) itemView.findViewById(R.id.tv_item_degree);

        }

        public void bindData(CarInfo mCarInfo) {
            if (!mCarInfo.getImageSrc().isEmpty()) {
                ivAvatar.setTag(mCarInfo.getImageSrc());
                x.image().bind(ivAvatar, mCarInfo.getImageSrc(), new Callback.CommonCallback<Drawable>() {
                    @Override
                    public void onSuccess(Drawable result) {

                    }

                    @Override
                    public void onError(Throwable ex, boolean isOnCallback) {
                        ivAvatar.setImageResource(R.mipmap.default_icon);
                    }

                    @Override
                    public void onCancelled(CancelledException cex) {

                    }

                    @Override
                    public void onFinished() {

                    }
                });
            } else {
                ivAvatar.setImageResource(R.mipmap.default_icon);
            }
            tv_car_id.setText("车牌号：" + mCarInfo.getLicenseNumber());
            tv_item_degree.setText(mCarInfo.getChName());

        }
    }
}
